<?php
namespace app\admin\validate;
use think\Validate;
use think\Db;

class Order extends Validate
{
    protected $rule = [
        'maphone'       =>  'require|yzphone:妈妈电话',
        'otherphone'    =>  'yzphone:家人电话',
        'weixin'        =>  'yzphone:微信',
        'qq'            =>  'yzphone:QQ',
    ];
    protected $message =[
        'maphone.require'=>'妈妈电话不能为空',
//        'maphone'=>'妈妈电话重复了s',
//        'otherphone'=>'家人电话号码重复了',
//        'weixin.'=>'微信不能重复',
//        'qq.require'=>'QQ不能重复',
    ];
    protected $scene = [
        'edit'  =>  [
            'maphone'   => 'require|unique:Order,maphone^id',
            'otherphone'=> 'require|unique:Order,otherphone^id',
            'weixin'    => 'require|unique:Order,weixin^id',
            'qq'        => 'require|unique:Order,qq^id',
        ]
    ];

    protected function yzphone($value, $rule, $data,$key){
        $info = Db::table('jtds_order')->where(['status'=>1,$key=>$value])->find();
        if($info){
            return $rule.'重复了';
        }else{
            return true;
        }
    }
}